#ifndef TREGIST_H
#define TREGIST_H

#include <Windows.h>
#include "tapi32u8.h"

#define MAX_KEYARRAY	30
class TRegistry
{
public:
	TRegistry( LPCSTR company, LPSTR appName = NULL, StrMode mode = BY_UTF8 );
	TRegistry( LPCWSTR company, LPCWSTR appName = NULL, StrMode mode = BY_UTF8 );
	TRegistry( HKEY topKey, StrMode mode = BY_UTF8 );
	~TRegistry();

	void ChangeTopKey( HKEY topKey );
	void SetStrMode( StrMode mode );

	bool ChangeApp( LPCSTR company, LPSTR appName = NULL );
	bool ChangeAppV( const void* company, const void* appName = NULL );

	bool OpenKey( LPCSTR subKey, bool createFlag = false );
	bool OpenKeyV( const void* subKey, bool createFlag = false );

	bool CreateKey( LPCSTR subKey ){ return OpenKey( subKey, true ); }
	bool CreateKeyV( const void* subKey ){ return OpenKeyV( subKey, true ); }

	bool DeleteKey( LPCSTR key );
	bool DeleteKeyV( const void* key );

	bool DeleteValue( LPCSTR str );
	bool DeleteValueV( const void* str );

	bool CloseKey( void );

	bool EnumKey( DWORD count, LPSTR buf, int size );
	bool EnumKeyV( DWORD count,void* buf, int size );

	bool EnumValue( DWORD count, LPSTR buf, int size, DWORD* type = NULL );
	bool EnumValueV( DWORD count, void* buf, int size, DWORD* type = NULL );

	bool GetInt( LPCSTR key, int* val );
	bool GetIntV( const void* key, int* val );
	bool SetInt( LPCSTR key, int val );
	bool SetIntV( const void* key, int val );

	bool GetLong( LPCSTR key, long* val );
	bool GetLongV( const void* key, long* val );
	bool SetLong( LPCSTR key, long val );
	bool SetLongV( const void* key, long val );

	bool GetStr( LPCSTR key, LPSTR str, int byteSize );
	bool GetStrA( LPCSTR key, LPSTR str, int byteSize );
	bool GetStrV( const void* key, void* str, int byteSize );
	bool SetStr( LPCSTR key, LPCSTR str );
	bool SetStrA( LPCSTR key, LPCSTR str );
	bool SetStrV( const void* key, const void* str );

	bool GetByte( LPCSTR key, BYTE* data, int* size );
	bool GetByteV( const void* key, BYTE* data, int* size );
	bool SetByte( LPCSTR key, BYTE* data, int size );
	bool SetByteV( const void* key, BYTE* data, int size );

	bool DeleteChildTree( LPCSTR subKey = NULL );
	bool DeleteChildTreeV( const void* subKey = NULL );

protected:
	HKEY	_topKey;
	int		_openCount;
	StrMode	_strMode;
	HKEY	_hKeys[MAX_KEYARRAY];
};

#endif	// TREGIST_H